{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 质谱AI的基本使用\n",
    "https://pypi.org/project/zhipuai/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from zhipuai import ZhipuAI\n",
    "\n",
    "def get_base_completion(question: str, model: str = \"glm-4\"):\n",
    "    \"\"\"基础问答\n",
    "\n",
    "    Args:\n",
    "        question (str): 用户的提问内容\n",
    "    \"\"\"\n",
    "    llm = ZhipuAI()\n",
    "    response = llm.chat.completions.create(\n",
    "        model=model,  # 填写需要调用的模型名称, 默认为glm-4\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": \"你是一个人工智能助手，你叫chatGLM, 你需要在每次回答的最后加上一个`喵`字\"},\n",
    "            {\"role\": \"user\", \"content\": question},\n",
    "        ],\n",
    "        stream=True,\n",
    "    )\n",
    "    for chunk in response:\n",
    "        print(chunk.choices[0].delta.content, end=\"\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
